import request from "@/utils/request";
import type { GetPermissionListResponse, SavePermissionApiParams, UpdatePermissionApiParams } from "./model/permissionModel";

enum Api {
  getPermissionList = "/admin/acl/permission",
  getRolePermission = "/admin/acl/permission/toAssign",
  assignRolePermission = "/admin/acl/permission/doAssign",
  savePermission = "/admin/acl/permission/save",
  updatePermission = "/admin/acl/permission/update",
  removePermission = "/admin/acl/permission/remove",
}

// 获取菜单分页列表
export const getPermissionListApi = () => {
  return request.get<any, GetPermissionListResponse>(Api.getPermissionList);
};

// 根据角色id获取菜单权限
export const getRolePermissionApi = (roleId: string) => {
  return request.get<any, GetPermissionListResponse>(`${Api.getRolePermission}/${roleId}`);
};

// 安排角色权限
export const assignRolePermissionApi = (roleId: string, permissionId: string[]) => {
  return request.post<any, null>(`${Api.assignRolePermission}?roleId=${roleId}&permissionId=${permissionId}`);
};

// 添加菜单
export const savePermissionApi = (permission: SavePermissionApiParams) => {
  return request.post<any, null>(Api.savePermission, permission);
};

// 修改菜单
export const updatePermissionApi = (permission: UpdatePermissionApiParams) => {
  return request.put<any, null>(Api.updatePermission, permission);
};

// 删除菜单
export const removePermissionApi = (id: string) => {
  return request.delete<any, null>(`${Api.removePermission}/${id}`);
};
